<?php

namespace App\Providers;

use App\Model\System\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;

class AuthServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Boot the authentication services for the application.
     *
     * @return void
     */
    public function boot()
    {
        $this->app['auth']->viaRequest('api', function ($request) {
            if ($request->cookie('token')) {
                $user =  User::where('token', $request->cookie('token'))->where('islock', 0)->first();
                if ($user){
                    $user->types = User::getUserTypes($user->userid);
                }
                return $user;
            }
        });
    }
}
